package com.dl.controller;

import com.dl.pojo.CoursePlan;
import com.dl.service.CoursePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class CoursePlanController {

    @Autowired
    private CoursePlanService coursePlanService;

    @RequestMapping("/add_courseplan_1.action")
    public ModelAndView add_courseplan_1(CoursePlan coursePlan, ModelAndView mav){
        int count = coursePlanService.addCoursePlan_1(coursePlan);
        if (count == 0){
            //failed
            mav.setViewName("fail.jsp");
        }else{
            mav.addObject("count",count);
            mav.setViewName("success.jsp");
        }
        return mav;
    }

    @RequestMapping("/add_courseplan_2.action")
    public ModelAndView add_courseplan_2(Integer setupid, Integer week, Integer day, Integer hour, Integer roomid, ModelAndView mav){
        int count = coursePlanService.addCoursePlan_2(setupid, week, day, hour, roomid);
        if (count == 0){
            //failed
            mav.setViewName("fail.jsp");
        }else{
            mav.addObject("count",count);
            mav.setViewName("success.jsp");
        }
        return mav;
    }

    @RequestMapping("/add_courseplan_4.action")
    public ModelAndView add_courseplan_4(Integer setupid, Integer week_0, Integer week_1, Integer day_0, Integer day_1, Integer hour_0, Integer hour_1, Integer roomid, ModelAndView mav){
        int count = coursePlanService.addCoursePlan_4(setupid, week_0, week_1, day_0, day_1, hour_0, hour_1, roomid);
        if (count == 0){
            //failed
            mav.setViewName("fail.jsp");
        }else{
            mav.addObject("count",count);
            mav.setViewName("success.jsp");
        }
        return mav;
    }
}
